package com.kool.kadmin.mqtt.constant;

import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author : luyu
 * @date :2021/3/26 14:10
 */
@Getter
public enum MqttUserStateEnum {
    ACTIVE(1, "激活"),
    CLOSED(2, "关闭");

    Integer code;
    String desc;

    MqttUserStateEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static Map<Integer, MqttUserStateEnum> enumMap = Arrays.stream(MqttUserStateEnum.values()).collect(Collectors.toMap(MqttUserStateEnum::getCode, item -> item));

    public static String getDescByCode(Integer code) {
        if (code == null) {
            return null;
        }
        MqttUserStateEnum mqttUserStateEnum = enumMap.get(code);
        if (mqttUserStateEnum == null) {
            return null;
        }
        return mqttUserStateEnum.getDesc();
    }
}
